package com.cn.wanxi.servlet.recruitment;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.OrdbyModel;
import com.cn.wanxi.model.PageModel;
import com.cn.wanxi.model.RecruitmentModel;
import com.cn.wanxi.service.IRecruitmentService;
import com.cn.wanxi.service.impl.RecruitmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/producat/recruitmentFindllTh")
public class recruitmentFindAllThServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.处理乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String startwages= req.getParameter("startwages");
        String endwages= req.getParameter("endwages");
        String address=req.getParameter("address");
        String phone=req.getParameter("phone");
        String position=req.getParameter("position");
        String startdate=req.getParameter("startdate");
        String enddate=req.getParameter("enddate");
        String ordbywages=req.getParameter("ordbywages");

        String pageNum=req.getParameter("pageNum");
        String pageSize=req.getParameter("pageSize");

        //3.封装到实体类UserModel
        OrdbyModel ordbyModel=new OrdbyModel();
        ordbyModel.setOrdbywages(ordbywages);
        PageModel pageModel=new PageModel();
        pageModel.setPageNum(pageNum==null || "".equals(pageNum)? 1 :Integer.parseInt(pageNum));
        pageModel.setPageSize(pageSize==null || "".equals(pageSize) ? 10:Integer.parseInt(pageSize));

        RecruitmentModel recruitmentModel=new RecruitmentModel();
        recruitmentModel.setStartwages(startwages);
        recruitmentModel.setEndwages(endwages);
        recruitmentModel.setAddress(address);
        recruitmentModel.setPhone(phone);
        recruitmentModel.setPosition(position);
        recruitmentModel.setPageModel(pageModel);
        recruitmentModel.setStartdate(startdate);
        recruitmentModel.setEnddate(enddate);
        recruitmentModel.setOrdbyModel(ordbyModel);


        IRecruitmentService iRecruitment=new RecruitmentServiceImpl();

        List<RecruitmentModel> list=iRecruitment.findAllTh(recruitmentModel);

        int number=iRecruitment.getCont(recruitmentModel);

        //7.将数据转发到页面
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("number",number);
        resp.getWriter().println(jsonObject);
    }
}
